#pragma once
#include "DContactGeom.h"
#include "DVector3.h"
#include "Geometries/DGeometry.h"

namespace Skill
{
	namespace Ode
	{
		void DContactGeom::CollectManagedMemory()
		{
			_Position = nullptr;
			_Normal = nullptr;			
		}

		int DContactGeom::SizeInBytes::get()
		{			
			return sizeof(dContactGeom);			
		}

		REF_PROP_DEFINITION_GET_FROM_REF(DContactGeom,pos,DVector3,Position);
		void DContactGeom::Position::set(DVector3^ value)
		{
			_This->pos[0] = value->_This[0];
			_This->pos[1] = value->_This[1];
			_This->pos[2] = value->_This[2];
			_This->pos[3] = value->_This[3];
		}

		REF_PROP_DEFINITION_GET_FROM_REF(DContactGeom,normal,DVector3,Normal);
		void DContactGeom::Normal::set(DVector3^ value)
		{
			_This->normal[0] = value->_This[0];
			_This->normal[1] = value->_This[1];
			_This->normal[2] = value->_This[2];
			_This->normal[3] = value->_This[3];
		}

		VALUE_PROP_DEFINITION_GETSET(DContactGeom,_This->depth,dReal,Depth);
		
		DGeometry^ DContactGeom::Geom1::get()
		{
			if(_This->g1)
			{				
					DIUnmanagedPointer^ p = DRegisteredObjects::Get(IntPtr(_This->g1));
					if(p)
						return dynamic_cast<DGeometry^>(p);									
			}
			return nullptr;
		}
		void DContactGeom::Geom1::set(DGeometry^ value)
		{			
			if(value)
				_This->g1 = value->_Geom();
			else _This->g1 = nullptr;
		}

		DGeometry^ DContactGeom::Geom2::get()
		{
			if(_This->g2)
			{				
					DIUnmanagedPointer^ p = DRegisteredObjects::Get(IntPtr(_This->g2));
					if(p)
						return dynamic_cast<DGeometry^>(p);								
			}
			return nullptr;
		}
		void DContactGeom::Geom2::set(DGeometry^ value)
		{
			if(value)
				_This->g2 = value->_Geom();
			else _This->g2 = nullptr;
		}

		VALUE_PROP_DEFINITION_GETSET(DContactGeom,_This->side1,int,Side1);
		VALUE_PROP_DEFINITION_GETSET(DContactGeom,_This->side2,int,Side2);				
	}
}